using System.Collections.Generic;
using System.Windows.Forms;

namespace LiteTools.tools
{
    public abstract class StringUtils
    {
        /// <summary>
        /// 根据给定的字符串决定显示的尺寸
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static Dictionary<string, int> GetSizeFromGivenStr(string context)
        {
            var maxWidth = (int)(Screen.PrimaryScreen.Bounds.Width * 0.75);
            var maxHeight = (int)(Screen.PrimaryScreen.Bounds.Height * 0.75);
            var currentWidth = 0;
            var currentHeight = 0;
            var split = context.Split('\n');
            foreach (var line in split)
            {
                if (line.Length * 13 > currentWidth)
                {
                    currentWidth = line.Length * 13;
                }

                currentHeight++;
            }

            if (currentWidth >= maxWidth)
            {
                currentWidth = maxWidth;
            }

            if (currentHeight * 30 >= maxHeight)
            {
                currentHeight = maxHeight;
            }
            else
            {
                currentHeight *= 30;
            }
            
            return new Dictionary<string, int>
            {
                {"w", currentWidth},
                {"h", currentHeight}
            };
        }
    }
}